/*
 *
 * *******************************************************************
 *   @项目名称: BHex Android
 *   @文件名称: CApplication.java
 *   @Date: 11/29/18 3:21 PM
 *   @Author: chenjun
 *   @Copyright（C）: 2018 BlueHelix Inc.   All rights reserved.
 *   注意：本内容仅限于内部传阅，禁止外泄以及用于其他的商业目的.
 *  *******************************************************************
 *
 */

package io.bhex.baselib.core;

import android.app.Application;
import android.content.Context;
import android.os.Handler;

import java.util.concurrent.Executor;

public abstract class CApplication extends Application {
    private static CApplication _instance;
    private static Context mBase;

    private static long expiredTime;

    private static Handler sHandler;

    @Override
    public void onCreate() {
        super.onCreate();
        _instance = this;
        sHandler = new Handler(_instance.getMainLooper());
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        mBase = base;
    }

    /**
     * 所有的新建线程，不要直接new thread，使用此线程池来做执行
     *
     * @return
     */
    public Executor getExecutor() {
        return AsyncTask.THREAD_POOL_EXECUTOR;
    }

    public static CApplication getInstance() {
        return _instance;
    }

    public static Context getMBaseContext() {
        return mBase;
    }

    public static void setMBaseContext(Context mBase) {
        CApplication.mBase = mBase;
    }

    public static void setExpiredTime(long time){
        expiredTime = time;
    }

    public static long expiredTime(){
        return expiredTime;
    }

    public static Handler getMainHandler() {
        return sHandler;
    }

}
